rendernode: Bail if matrix is invalid
authorBenjamin Otte <otte@redhat.com>
Thu, 24 Dec 2020 05:32:17 +0000 (06:32 +0100)
committerBenjamin Otte <otte@redhat.com>
Thu, 24 Dec 2020 05:38:45 +0000 (06:38 +0100)
Invalid matrices are okay in GSK (and GL), but not in Cairo.

Testcase included.

gsk/gskrendernodeimpl.c
testsuite/gsk/compare/invalid-transform.node [new file with mode: 0644]
testsuite/gsk/compare/invalid-transform.png [new file with mode: 0644]
testsuite/gsk/meson.build

index aa19233f4e6da90a59b063bb9cc09ff3c1fcd694..6d9a3fd50f861dc2317d4b67cf9d21b5e042a943 100644 (file)
@@ -2755,6 +2755,16 @@ gsk_transform_node_draw (GskRenderNode *node,
                             ctm.xx, ctm.yx,
                             ctm.xy, ctm.yy,
                             ctm.x0, ctm.y0));
+  if (xx * yy == xy * yx)
+    {
+      /* broken matrix here. This can happen during transitions
+       * (like when flipping an axis at the point where scale == 0)
+       * and just means that nothing should be drawn.
+       * But Cairo thows lots of ugly errors instead of silently
+       * going on. So We silently go on.
+       */
+      return;
+    }
   cairo_transform (cr, &ctm);
 
   gsk_render_node_draw (self->child, cr);
diff --git a/testsuite/gsk/compare/invalid-transform.node b/testsuite/gsk/compare/invalid-transform.node
new file mode 100644 (file)
index 0000000..3e34173
--- /dev/null
@@ -0,0 +1,16 @@
+transform {
+  /* break the transform on purpose, because
+     this is valid in GSK and should result
+     in nothing being drawn. */
+  transform: scale(0);
+  child: color {
+    color: red;
+    bounds: 0 0 100 100;
+  }
+}
+
+/* make sure the rendering has a size */
+color {
+  color: transparent;
+  bounds: 0 0 1 1;
+}
\ No newline at end of file
diff --git a/testsuite/gsk/compare/invalid-transform.png b/testsuite/gsk/compare/invalid-transform.png
new file mode 100644 (file)
index 0000000..7238a64
Binary files /dev/null and b/testsuite/gsk/compare/invalid-transform.png differ
index ccd29dff5b544e74a543abbeb9393efc18d8db36..c23d371e3e31f1a0166d57d277a42f086af55133 100644 (file)
@@ -48,6 +48,7 @@ compare_render_tests = [
   'empty-shadow',
   'empty-texture',
   'empty-transform',
+  'invalid-transform',
   'opacity_clip',
   'outset_shadow_offset_both',
   'outset_shadow_offset_x',